//
//  HotListViewController.m
//  滴滴快拍
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HotListViewController.h"
#import "FJC_SwipeableView.h"
#import "FJC_AVswipeCardCell.h"
#import "FJC_AVCardInfo.h"

@interface HotListViewController ()<FJC_SwipeableViewDataSource, FJC_SwipeableViewDelegate>

@property (nonatomic, strong) NSMutableArray *cardInfoList;
@property (nonatomic, strong) FJC_SwipeableView *swipeableView;

@end

@implementation HotListViewController

- (NSMutableArray *)cardInfoList {
    if (!_cardInfoList) {
        _cardInfoList = [NSMutableArray array];
    }
    return _cardInfoList;
}

- (FJC_SwipeableView *)swipeableView {
    
    if (!_swipeableView) {
        _swipeableView = [[FJC_SwipeableView alloc] initWithFrame:self.view.bounds];
        _swipeableView.datasource = self;
        _swipeableView.delegate = self;
        _swipeableView.backgroundColor = [UIColor whiteColor];
        _swipeableView.topCardInset = UIEdgeInsetsMake(20, 20, 20, 20);
        _swipeableView.hidden = YES;
    }
    return _swipeableView;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"热榜";
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self.view addSubview:self.swipeableView];
    self.swipeableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.swipeableView registerClass:[FJC_AVswipeCardCell class] forCellReuseIdentifier:@"reuseCell"];
    
    for (int i = 0; i < 100; i++) {
        FJC_AVCardInfo *info = [[FJC_AVCardInfo alloc] init];
        [self.cardInfoList addObject:info];
    }
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.swipeableView.hidden = NO;
        [self.swipeableView reloadData];
    });
    
    
    
}

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.swipeableView.frame = self.view.bounds;
}
// DataSource协议方法
- (NSInteger)swipeableViewNumberOfRowsInSection:(FJC_SwipeableView *)swipeableView{
    return self.cardInfoList.count;
}

- (FJC_SwipeableViewCell *)swipeableView:(FJC_SwipeableView *)swipeableView cellForIndex:(NSInteger)index{
    FJC_AVswipeCardCell *cell = [swipeableView dequeueReusableCellWithIdentifier:@"reuseCell"];
    cell.backgroundColor = [UIColor blueColor];
    return cell;
}

- (FJC_SwipeableViewCell *)swipeableView:(FJC_SwipeableView *)swipeableView substituteCellForIndex:(NSInteger)index{
    FJC_AVswipeCardCell *cell = [[FJC_AVswipeCardCell alloc] init];
    return cell;
}

- (NSInteger)swipeableViewMaxCardNumberWillShow:(FJC_SwipeableView *)swipeableView{
    return 4;
}
- (void)swipeableView:(FJC_SwipeableView *)swipeableView didTapCellAtIndex:(NSInteger)index{
    
}



// 拉到最后一个
- (void)swipeableViewDidLastCardRemoved:(FJC_SwipeableView *)swipeableView{
    
//    [self.swipeableView reloadData];
    
}

- (void)swipeableView:(FJC_SwipeableView *)swipeableView didCardRemovedAtIndex:(NSInteger)index withDirection:(FJC_SwipeableViewCellSwipeDirection)direction{
    NSLog(@"%zd",direction);
}


- (void)swipeableView:(FJC_SwipeableView *)swipeableView didTopCardShow:(FJC_SwipeableViewCell *)topCell{
    
}


- (void)swipeableView:(FJC_SwipeableView *)swipeableView didLastCardShow:(FJC_SwipeableViewCell *)cell{
    
}

// Delegate协议方法
- (void)knackBottomToolViewDidCheckDetailBtnClick:(FJC_AVCardInfo *)idInfo{
    [self.swipeableView removeTopCardViewFromSwipe:FJC_SwipeableViewCellSwipeDirectionLeft];
}


- (void)knackBottomToolViewDidCollectBtnClick:(FJC_AVCardInfo *)idInfo{
    [self.swipeableView removeTopCardViewFromSwipe:FJC_SwipeableViewCellSwipeDirectionRight];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
